<template>
    <div class="data">
      <!-- 头部 -->
			<div class="dataHeader">
				<div class="search">
          <el-input style="width:200px; float:left;" v-model="appname" placeholder="输入app名称"></el-input>
					<!-- <div class="block" style="width:200px; float:left; margin-left:10px;">
						<el-date-picker v-model="value1"	type="date" placeholder="选择日期">
						</el-date-picker>
					</div> -->
				</div>
				<el-button class="seachBtn_actual" @click="actualSeach(appname)" type="primary">搜索</el-button>
        <div class="rightBox">
          <div class="btn">
            <el-upload :action="actionUrl()" :on-success="handleAvatarSuccess">
              <el-button type="primary">导入</el-button>
            </el-upload> 
          </div>
          <div class="btn">
            <el-button @click="actualExport(appname)" type="primary">导出</el-button>
          </div>
        </div>
			</div>

      <!-- 内容 -->
      <div class="dataContent">
        <el-table  :data="actualList" border style="width: 100%">
          <el-table-column fixed prop="curdate" label="日期" width="120">
             <template slot-scope="scope"> 
              {{scope.row.curdate.split(" ")[0]}}
            </template>
          </el-table-column>
          <el-table-column fixed prop="appName" label="app名称" width="130">
          </el-table-column>
          <el-table-column fixed prop="appKey" label="appkey" width="280">
          </el-table-column>
          <el-table-column fixed prop="actual" label="本次收益" width="140">
          </el-table-column>
          <el-table-column fixed prop="availWallet" label="可提现收益" width="130">
          </el-table-column>
          <el-table-column fixed prop="totalWallet" label="累计总收益" width="130">
          </el-table-column>
          <el-table-column fixed prop="" label="已提现收益" width="">
              <template slot-scope="scope">
                {{(scope.row.totalWallet-scope.row.availWallet).toFixed(2)}}
             </template>
          </el-table-column>
          <el-table-column fixed prop="" label="渠道链接" width="200">
           <template slot-scope="scope">
              <span v-if="scope.row.channelUrl">{{scope.row.channelUrl}}</span>
            </template>
          </el-table-column>
      
          </el-table>
      </div>

      <!-- 分页 -->
      <div class="pagination">
        <el-pagination 
        @current-change="handleCurrentChange" 
        :current-page.sync="currentPage" 
        :page-size="10" 
        layout="total, prev, pager, next" :total="this.total">
        </el-pagination>
      </div>

    </div>
</template>

<script>
import http_url from "@/http/http";
export default {
  data() {
    return {
      actualList: [],
      page: 1,
      rows: 10,
      value1: "",
      appname: "",
      currentPage: 1,
      total: 0
    };
  },
  mounted() {
    this.actual();
  },
  methods: {
    //实际收入列表
    actual() {
      this.$http({
        method: "POST",
        url: http_url.BASE_URL + "/actual/pagelist.do",
        data: `page=${this.page}&rows=${this.rows}&appName=${this.appname}`
      }).then(res => {
        console.log(res);
        if (res.data.code == 0) {
          this.actualList = res.data.data.list;
          this.total = res.data.data.total;
        }
        // console.log(this.actualList);
      });
    },
    // 实际入数据导出
    actualExport(appname, date) {
      // console.log(appname);
      // console.log(http_url.getTaskTime(date));
      window.location.href = encodeURI(
        encodeURI(
          http_url.BASE_URL +
            "/actual/export.do?appName=" +
            appname +
            "&dealdate=" +
            http_url.getTaskTime(date)
        )
      );
    },
    //实际收入搜索
    actualSeach(appname, dealdate) {
      this.appname = appname;
      this.actual();
    },
    //导入
    actionUrl() {
      return http_url.BASE_URL + "/actual/upload.do";
    },
    handleAvatarSuccess(res, file) {
      let type = file.name.split(".")[1];
      if (type == "xlsx" || type == "xls" || type == "xlsm") {
        if (res.code == 0) {
          this.$message({
            message: res.message,
            type: "success"
          });
          this.actual();
        } else {
          this.$message({
            message: res.message,
            type: "warning"
          });
        }
      } else {
        this.$message({
          message: "上传文件格式不正确",
          type: "warning"
        });
        return;
      }
    },
    //分页
    handleCurrentChange(val) {
      this.page = val;
      this.actual();
    }
  }
};
</script>

<style lang="scss" scoped>
.data {
  width: 100%;
  height: calc(100% - 50px);
  padding: 10px;
  .dataHeader {
    height: 40px;
    width: 100%;
    margin-top: 5px;
    position: relative;
    margin-bottom: 20px;
    .seachBtn_actual {
      position: absolute;
      left: 250px;
      top: 0;
    }
    .search {
      width: 450px;
      height: 100%;
      position: relative;
      .search .searchInp {
        width: 150px;
        display: inline-block;
        background: red;
        border: 1px solid red;
      }
      .search .block {
        position: absolute;
        right: 30px;
        top: 0px;
      }
    }
    .rightBox {
      width: 200px;
      height: 100%;
      position: absolute;
      right: 0;
      top: 0;
      overflow: hidden;
      .btn {
        width: 50%;
        float: left;
        text-align: center;
        #prodImageUpload {
          position: absolute;
          right: 120px;
          top: 0;
          width: 60px;
          height: 36px;
          opacity: 0;
        }
      }
    }
  }
  .dataContent {
    height: calc(100% - 150px);
    overflow-y: scroll;
    th,
    td {
      text-align: center;
    }
    td {
      font-size: 14px;
    }
  }
  .pagination {
    position: absolute;
    bottom: 50px;
    left: calc(50% - 145px);
    text-align: center;
  }
}
</style>
